package com.fowo.api.service.handleWork;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.fowo.api.entity.*;
import com.fowo.api.model.payable.PayableVo;
import com.fowo.api.model.payable.product.PayableProductItemVo;
import com.fowo.api.model.process.product.ProcessProductProcessProductPushJindieAction;
import com.fowo.api.service.impl.*;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;


//生成应付单
@Component
public class processProductProcessProductPushJindie implements ProcessProductProcessProductPushJindieAction {
    @Override
    public void run(Long id) throws Exception {

    }


//    @Resource
//    private ProcessProductServiceImpl processProductService;
//
//    @Resource
//    protected ProcessProductItemServiceImpl processProductItemService;
//    @Resource
//    private PayableServiceImpl payableService;
//    @Resource
//    private PayableProductServiceImpl payableProductService;
//    @Override
//    public void run(Long id) throws Exception {
//         ProcessProduct byId = processProductService.getById(id);
//         Assert.isTrue(byId.getStatus().equals("1"),"未审核！");
////         Assert.isTrue(byId.getGenerateAp().equals("0"),"已经生成应付单！");
//         List<ProcessProductItem> list = processProductItemService.list(Wrappers.<ProcessProductItem>query().lambda().eq(ProcessProductItem::getParentProcessProduct, id));
//         addPayable(byId,list);
//    }
//
//    @Transactional(rollbackFor = Exception.class)
//    public void addPayable(ProcessProduct byId, List<ProcessProductItem> list) {
//        PayableVo model =new PayableVo();
//        model.setStauts("0");
////        model.setPayOrg(byId.getDepId());
////        model.setPurchasesOrg(byId.getDepId());
////        model.setSettlementOrg(byId.getDepId());
////        model.setRemarks(byId.getRemarks()!=null?byId.getRemarks()+",加工单:"+byId.getCode():"加工单:"+byId.getCode());
////        model.setBusinessDate(byId.getProcessingDate());
////        model.setSupplierId(byId.getSupplierId());
//        model.setProductType("3");
//        model.setPushStatus("0");
//        List<PayableProductItemVo> productltem=new ArrayList<>();
//        for(int i=0;i<list.size();i++){
//            ProcessProductItem processProductItem = list.get(i);
//            PayableProductItemVo payableProductItemVo=new PayableProductItemVo();
//            payableProductItemVo.setNum(processProductItem.getNum().intValue());
//            payableProductItemVo.setProductId(processProductItem.getProductId());
//            payableProductItemVo.setSku(processProductItem.getSku());
//            payableProductItemVo.setSubtotal(processProductItem.getSubtotal());
//            productltem.add(payableProductItemVo);
//        }
//        model.setProductltem(productltem);
//        try {
//            payableService.create(model);
//        } catch (Exception e) {
//            throw new RuntimeException("");
//        }
////        byId.setGenerateAp("1");
//        processProductService.updateById(byId);
//    }

}
